* ********************************************************************************************
* The Effects of Weather Shocks on Economic Activity: What are the Channels of Impact?
* Sebastian Acevedo, Mico Mrkaic, Natalija Novta, Evgenia Pugacheva, Petia Topalova
* With support from Gavin Asdorian, Olivia Ma, Jilun Xing and Yuan Zeng 
* Replication files for Table 4; Figure 8
* ********************************************************************************************
clear all
set more off
set matsize 11000

cd "C:\Users\..\replication" // set your working directory to where the replication folder is saved

* the Y variable that will be used in regressions
local Y_list ava_rlcu_wdi ag_prd_crop mva_rlcu_wdi sva_rlcu_wdi ni_r nm_r mrt_i hdi

* Horizons
global k 7


* ****************************************************************************************
* Data
* ****************************************************************************************
use "data/subnational_dataset.dta", clear

* temperature, keep sample within [15; 20]
bys provcode: egen mn_pwtemp = mean(pwtemp)
keep if inrange(mn_pwtemp, 15, 20)

foreach X in pwtemp pwprecip {
	gen `X'2=`X'^2
}

gen sqyear=year^2

by provcode (year), sort: gen d0_ln_gdppc = ln_gdppc - l.ln_gdppc
forval t = 1/$k {
	by provcode (year), sort: gen d`t'_ln_gdppc = f`t'.ln_gdppc - l.ln_gdppc
}

* Create WDI region year fixed effects
gen tempvar1 = wdi_region + " " + string(year) if wdi_region != ""
encode tempvar1, generate(ry)
drop tempvar1

xi i.ifscode*year i.ifscode*sqyear  i.ry i.year
* interact the RY with the AE dummy
xi i.ae*i.ry
gen l_d0_ln_gdppcl_ae = ae* l.d0_ln_gdppc

areg d0_ln_gdppc pwtemp pwprecip l.pwtemp l.pwprecip l.d0_ln_gdppc _Iry_*, cluster(provcode) absorb(provcode)

keep if e(sample)


sum pwtemp, det

sum pwtemp if ae == 1, det

sum pwtemp if ae == 0, det

